﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Oragon.Architecture.Data.SqlBuilder
{
	public class DeleteSQLBuilder : ISQLStatement, ICloneble<DeleteSQLBuilder>
	{
		public SqlLiteral TableName { get; set; }
		public WhereClause WhereClause { get; set; }

		public DeleteSQLBuilder()
		{
			this.TableName = null;
			this.WhereClause = new WhereClause();
		}

		public DeleteSQLBuilder Clone()
		{
			System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			serializer.Serialize(stream, this);
			stream.Position = 0;
			DeleteSQLBuilder newInstance = (DeleteSQLBuilder)serializer.Deserialize(stream);
			stream.Close();
			return newInstance;
		}


		public string ToSQL()
		{
			System.IO.StringWriter SQL = new System.IO.StringWriter(System.Globalization.CultureInfo.InvariantCulture);
			SQL.WriteLine("DELETE FROM {0}", this.TableName.ToSQL());
			SQL.Write(this.WhereClause.ToSQL());
			return SQL.ToString();
		}

	}
}
